<?php
    $url = new Url();
    $arrTypeSanPham = LoadConfig::$arrayTypeSanPham;
?>
<div class="left">
    <?php $this->widget("AdminMenuDoithuong")?>
</div>
<div class="right-main">
    <div class="righ-cont">
        <div class="right">
            <div class="title_style"> <strong class="clred">Quản trị đổi thưởng</strong></div>
            <form action="" method="get">
                <div class="tool clearfix bottom15">
                    <ul class="form4">
                        <li class="clearfix">
                            <label><strong>Từ khóa :</strong></label>
                            <div class="filltext">
                                <input type="text" value="<?=$key_word?>" name="key_word" style="width:223px;margin-right:10px;">
                                <select style="width:100px;height: 22px;" name="type_key">
                                    <option value="1" <?=$type_key == 1 ? "selected='selected'":"" ?>>Username</option>
                                    <option value="2" <?=$type_key == 2 ? "selected='selected'":"" ?>>Số điện thoại</option> 
                                </select>
                            </div>
                        </li>
                        <li class="clearfix">
                            <label><strong>Quà đổi thưởng :</strong> </label>
                            <div class="filltext">
                                <select style="width:235px; height: 22px;" id="type" name="type">
                                    <option value ="0">Tất cả</option>
                                    <?php foreach($arrTypeSanPham as $key=>$value){?>
                                        <option value ="<?=$key?>" <?=$type == $key ? "selected='selected'":""?>><?=$value?></option>
                                        <?php }?> 
                                </select>
                            </div>
                        </li>
                        <li class="clearfix">
                            <label><strong>Trạng thái :</strong> </label>
                            <div class="filltext">
                                <select style="width:235px;height: 22px;" id="status" name="status">
                                    <option value="-1">Tất cả</option> 
                                    <option value="0" <?=$status == 0 ? "selected='selected'":""?>>Chưa trả thưởng</option>
                                    <option value="1" <?=$status == 1 ? "selected='selected'":""?>>Đã trả thưởng</option> 
                                </select>
                            </div>
                        </li>
                        <li class="clearfix">
                            <label><strong>Thời gian :</strong> </label>
                            <div class="filltext"> Từ:&nbsp; 
                                <?php        
                                    $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                                    'name'=>'fromDate',
                                    'value'=>$formDate,
                                    'options'=>array(
                                    'showAnim'=>'fold',

                                    'dateFormat'=>'dd/mm/yy',
                                    'changeYear'=>'true', 

                                    ),
                                    'htmlOptions'=>array(
                                    'style'=>'width:70px',
                                    'class'=>'form',
                                    ),
                                    ));

                                ?> &nbsp;Đến:&nbsp; 
                                <?php        
                                    $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                                    'name'=>'toDate',
                                    'value'=>$toDate,
                                    'options'=>array(
                                    'showAnim'=>'fold',

                                    'dateFormat'=>'dd/mm/yy',
                                    'changeYear'=>'true', 

                                    ),
                                    'htmlOptions'=>array(
                                    'style'=>'width:70px',
                                    'class'=>'form',
                                    ),
                                    ));                                     
                                ?> 
                            </div>
                        </li>
                        <li class="clearfix">
                            <label>&nbsp; </label>
                            <div class="filltext">
                                <input type="submit" class="button" value="Tìm kiếm">
                            </div>
                        </li>
                    </ul>
                </div>
            </form>
            <?php if($count_data > 0){?>
                <hr />
                <div class="fillters clearfix">
                    <div class="fl"><span class="s14">Tổng số: <strong class="clred"><?=$count_data?></strong> hóa đơn</span></div>
                    <ul class="paging fr">
                        <?=isset($page)?$page:""?>
                    </ul>
                </div>
                <div class="table clearfix">

                    <table cellspacing="0" cellpadding="0" border="0" width="100%">
                        <tbody>
                            <tr class="bg_gray">
                                <td width="5%"><strong>STT</strong></td>
                                <td width="11%"><strong>Thời gian</strong></td>
                                <td width="16%"><strong>Thông tin tài khoản</strong></td>
                                <td width="23%"><strong>Quà đổi thưởng</strong></td>
                                <td width="14%"><strong>Tổng giá trị</strong></td>
                                <td width="20%"><strong>Thông tin người nhận</strong></td>
                                <td width="11%"><strong>Trạng thái trả thưởng</strong></td>
                            </tr>
                            <?php foreach($data as $key=>$value){?>
                                <tr>
                                    <td><?=$begin+$key+1?></td>
                                    <td><p><?=date("d/m/Y",$value['create_date'])?></p> <p><?=date("h:i A",$value['create_date'])?></p></td>
                                    <td class="text-left">
                                        <ul class="list">
                                            <li>User name: <?=$value['user_name']?></li>
                                            <li>Số ĐT: <?=$value['user_mobile']?></li> 
                                            <li>TK lúc đổi thưởng: <strong class="clred"><?=StringUtils::formatNumber($value['tk_lucdoithuong'])?></strong> dong</li> 
                                        </ul>
                                    </td>
                                    <td class="text-left">
                                        <?php foreach($item[$key] as $key_i=>$value_i){?>
                                            <p><strong class="clred"><?=$key_i+1?>. <?=$value_i['giaithuong_name']?></strong></p>
                                            <ul class="list">
                                                <li> Đơn giá: <?=StringUtils::formatNumber($value_i['price'])?></li>
                                                <li> Số lượng:  <?=$value_i['quantity']?></li>
                                                <li> Thành tiền: <?=StringUtils::formatNumber($value_i['price']*$value_i['quantity'])?></li>
                                            </ul>
                                            <?php }?>
                                    </td>
                                    <td class="text-left"><?=StringUtils::formatNumber($value['tong_tien'])?> dong</td>
                                    <td class="text-left">
                                        <ul class="list">
                                            <li> Tên người nhận: <?=$value['receiver_name']?></li>
                                            <li> Địa chỉ: <?=$value['receiver_address']?></li>
                                            <li> Số ĐT Liên hệ: <?=$value['receiver_phone']?></li>
                                            <li> Email: <?=$value['receiver_email']?></li>
                                        </ul>
                                    </td>
                                    <td>
                                        <input type="checkbox" onclick="updateStatus(<?=$value['id']?>,<?=$value['status']?>)" <?=$value['status']==1?"checked='checked'":""?> value="" name="" />
                                        <?php if($value['status'] > 0){?>
                                            <p><?=date("d/m/Y",$value['modify_date'])?></p> <p><?=date("h:i A",$value['modify_date'])?></p>
                                            <?php }?>
                                    </td>
                                </tr>
                                <?php }?>
                        </tbody>
                    </table>
                </div>
                <div class="fillters clearfix">
                    <ul class="paging fr">
                        <?=isset($page)?$page:""?> 
                    </ul>
                </div>
                <?php }?>
        </div>
    </div>
</div>
<script type="">
    function updateStatus(id,current_status){
        var new_status = 1;
        if(current_status == 1){
            new_status = 0;    
        }
        var strUrl = "<?=$url->createUrl("doithuong/updateStatus")?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: { id      :id,
                    status  :new_status
            },
            success: function(msg){  
                if(msg!=0){     
                    location.reload(); 
                }else{
                    alert("Lỗi!"); 
                    location.reload();
                } 
            }
        });
    }
</script>
